import * as bm from "/js/baseModule.js";

export class Module extends bm.baseModule {
    constructor(view) {
        super(view);
        var that = this;
        this._sign = "";
        this._saveTarget = this.find('.active');
        let vueDom = this.find("#news_vue").get(0);
        let user = globalData.user;
        let unread = globalData.unread_num;
        new Vue({
            el: vueDom,
            data: {
                isActive: false,
                unread: unread
            },
            computed: {
                unreadCom: function () {
                    if (this.unread.private_unread > 9) {
                        return '…';
                    }
                    return this.unread.private_unread;
                }
            }
        });
        // this.rightDialog = new tdom.CommonDialog({
        //     className: "rightMenu",
        //     effect: tdom.DialogEffect.slideLeft,
        //     masked: true,
        //     size: { width: 300, height: tomato.DialogSize.Full },
        //     position: { x: tomato.DialogPosition.Right, y: tomato.DialogPosition.Top },
        //     bodyEffect: tdom.TurnEffect.slid,
        //     asideEffect: tdom.TurnEffect.slid,
        // });
        // this.rightDialog.close = function (): boolean {
        //     that._evt_openBlock("", that._saveTarget, that._saveHit)
        //     return tdom.CommonDialog.prototype.close.call(this, false);
        // }
        // tomato.application.appendChild(this.rightDialog);
    }
    _evt_openBlock(target, hit) {
        var that = this;
        var name = target.innerHTML;
        var sign = $(target).attr("sign");
        if (that._sign == sign) {
            return;
        }
        if (sign == "Index") {
            that._saveTarget = target;
            that._saveHit = hit;
            //发现
            // tomato.getVPresenter<tomato.VPresenter>(funs.moduleToUrl('m/Index'), (Index) => {
            //     funs.loadPage(Index);
            // })
        } else if (sign == "Message") {
            //如果是游客/客户点击了需要登录的选项
            // if (globalData.user.user_type != 100) {
            //     let type = 1;
            //     if(globalData.user.user_type == 1){
            //         type = 2;
            //     }
            //     $(document).trigger('openLoginModal',[false,type]);
            //     return
            // }
            // that._saveTarget = target;
            // that._saveHit = hit;
            //消息
            // tomato.getVPresenter<tomato.VPresenter>(funs.moduleToUrl('m/project/JoinedProjects'), (JoinedProjects) => {
            //     funs.loadPage(JoinedProjects);
            // })
            funs.openModal('modules/modals/CommonModal.JS',function (mod) {
                mod.setType(11);
            })
        }
        else if (sign == "UserNav") {
            //如果是游客/客户点击了需要登录的选项
            if (globalData.user.user_type != 100) {
                let type = 1;
                if(globalData.user.user_type == 1){
                    type = 2;
                }
                $(document).trigger('openLoginModal',[false,type]);
                return
            }
            funs.swipeModule('modules/user/UserNav.js','66%','left',function () {
                console.log('111');
            })
        }
        /**移除所有active */
        that.classReset();
        $(target).addClass('active');
        $(target).children("span:first").attr('class', $(target).children("span:first").attr('class') + '1');

    }

    backIndex(){
        this._evt_openBlock(this.find('.faxian')[0], this._saveHit);
    }
    /**移除所有active */
    classReset() {
        this.find('.foot-block').removeClass('active');
        this.find('.faxian').children("span:first").attr('class', 'icon-faxian');
        this.find('.news').children("span:first").attr('class', 'icon-news');
        this.find('.me').children("span:first").attr('class', 'icon-me');
    }
}